package org.htmlparser.http;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class HttpHeader
{
  public static String getRequestHeader(HttpURLConnection paramHttpURLConnection)
  {
    StringBuffer localStringBuffer = new StringBuffer(1024);
    localStringBuffer.append(paramHttpURLConnection.getRequestMethod());
    localStringBuffer.append(" ");
    localStringBuffer.append(paramHttpURLConnection.getURL());
    localStringBuffer.append(" HTTP/1.1\n");
    Map localMap = paramHttpURLConnection.getRequestProperties();
    Iterator localIterator = localMap.keySet().iterator();
    while (localIterator.hasNext())
    {
      String str = (String)localIterator.next();
      List localList = (List)localMap.get(str);
      localStringBuffer.append(str);
      localStringBuffer.append(": ");
      for (int i = 0; i < localList.size(); ++i)
      {
        if (i != 0)
          localStringBuffer.append(", ");
        localStringBuffer.append(localList.get(i));
      }
      localStringBuffer.append("\n");
    }
    return localStringBuffer.toString();
  }

  public static String getResponseHeader(HttpURLConnection paramHttpURLConnection)
  {
    StringBuffer localStringBuffer = new StringBuffer(1024);
    while (true)
    {
      int j;
      try
      {
        int i = paramHttpURLConnection.getResponseCode();
        if (-1 != i)
        {
          String str1 = paramHttpURLConnection.getResponseMessage();
          j = 0;
          String str2 = paramHttpURLConnection.getHeaderField(j);
          if (str2 != null)
          {
            String str3 = paramHttpURLConnection.getHeaderFieldKey(j);
            if ((str3 == null) && (j == 0))
            {
              localStringBuffer.append("HTTP/1.1 ");
              localStringBuffer.append(i);
              localStringBuffer.append(" ");
              localStringBuffer.append(str1);
              localStringBuffer.append("\n");
              break label153:
            }
            if (str3 != null)
            {
              localStringBuffer.append(str3);
              localStringBuffer.append(": ");
            }
            localStringBuffer.append(str2);
            localStringBuffer.append("\n");
          }
        }
      }
      catch (IOException localIOException)
      {
        localStringBuffer.append(localIOException.toString());
        return localStringBuffer.toString();
      }
      label153: ++j;
    }
  }
}